import nattyFetch from 'natty-fetch';
import nattyStorage from 'natty-storage';
import { Toast } from 'saltui';
import Loading from 'components/loading';
import { urlPrefix, isDev,URLS } from './variables';

// See https://github.com/Jias/natty-fetch for more details.
const context = nattyFetch.context({
  mockUrlPrefix: urlPrefix,
  urlPrefix,
  mock: isDev,
  // jsonp: true,
  withCredentials: false,
  traditional: true,
  header:{
    Authorization:'Bearer '+getLoginUserInfo().token,
  },
  data: {
    _tb_token_: '',
  },
  timeout: 0,
  didFetch: () => Toast.hide(),
  // 请按照需要开启
  fit(response) {
    return {
      success: response.success,
      content: response.content,
      error: {
        errorMsg: response.errorMsg,
        errorCode: response.errorCode,
        errorLevel: response.errorLevel,
      },
    };
  },
});

// const storage = nattyStorage({
//   type:'localStorage',  // 缓存方式, 默认为'localStorage'
//   key:'meeting',   
// });

context.create('SomeModuleAPI', {
  getSomeInfo: {
    mockUrl: 'query/getSomeInfo.json',
    url: 'query/getSomeInfo.json',
    willFetch() {
      Toast.show({
        type: 'loading',
        content: 'Loading',
      });
    },
  },
  meetingDetail: {
    url: URLS.meetingDetail,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  attendNoticeInfoSetList: {
    url: URLS.attendNoticeInfoSetList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  
  approval: {
    url: URLS.approval,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  
  createApplyRecordList: {
    url: URLS.createApplyRecordList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  
  attendApplyRecordList: {
    url: URLS.attendApplyRecordList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  getReceiptStatistics: {
    url: URLS.getReceiptStatistics,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  applyBoardroomList: {
    url: URLS.applyBoardroomList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  murl: {
    url: URLS.murl,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  canUseBoardroomList: {
    url: URLS.canUseBoardroomList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  receivedNoticeList: {
    url: URLS.receivedNoticeList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  editNoticeInfoStatus: {
    url: URLS.editNoticeInfoStatus,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  turnoverSave: {
    url: URLS.turnoverSave,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  changMemoUser: {
    url: URLS.changMemoUser,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  sendNoticeList: {
    url: URLS.sendNoticeList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  getCycleMeetingList: {
    url: URLS.getCycleMeetingList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  getCycleMeetingByCycleId: {
    url: URLS.getCycleMeetingByCycleId,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  getBoardRoomServeTreeData: {
    url: URLS.getBoardRoomServeTreeData,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  
  attendNoticeInfo: {
    url: URLS.attendNoticeInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  entityIsExist: {
    url: URLS.entityIsExist,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  cycleEntityIsExist: {
    url: URLS.cycleEntityIsExist,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  taskIsExist: {
    url: URLS.taskIsExist,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  memoIsExist: {
    url: URLS.memoIsExist,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  saveTurnoverInfo: {
    url: URLS.saveTurnoverInfo,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  
  checkTurnoverDate: {
    url: URLS.checkTurnoverDate,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  transmitMemo: {
    url: URLS.transmitMemo,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  
  deleteMemoInfo: {
    url: URLS.deleteMemoInfo,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  sendMeetingRemind: {
    url: URLS.sendMeetingRemind,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  applyRecordInfo: {
    url: URLS.applyRecordInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getCreatedbyNameAndApplyInfo: {
    url: URLS.getCreatedbyNameAndApplyInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  canStartMeeting: {
    url: URLS.canStartMeeting,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  saveApplyBoardroomCycleMeeting: {
    url: URLS.saveApplyBoardroomCycleMeeting,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
       content: <Loading/>,
      });
    },
  },
  editSaveWithoutNotice: {
    url: URLS.editSaveWithoutNotice,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
       content: <Loading/>,
      });
    },
  },
  saveInfo: {
      url: URLS.saveInfo,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        Toast.show({
         content: <Loading/>,
        });
      },
    },
  editSignedInfo: {
      url: URLS.editSignedInfo,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        Toast.show({
         content: <Loading/>
        });
      },
    },
  editNoticeInfo: {
      url: URLS.editNoticeInfo,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        Toast.show({
         content: <Loading/>,
        });
      },
    },
  editApplyRecordInfo: {
      url: URLS.editApplyRecordInfo,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        Toast.show({
         content: <Loading/>,
        });
      },
    },
  changeByStatusBpm: {
      url: URLS.changeByStatusBpm,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        /*Toast.show({
         content: <Loading/>,
        });*/
      },
    },
    deleteApplyBoardroom: {
      url: URLS.deleteApplyBoardroom,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        Toast.show({
         content: <Loading/>,
        });
      },
    },
  deletApplyRecordInfo: {
      url: URLS.deletApplyRecordInfo,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        Toast.show({
         content: <Loading/>,
        });
      },
    },
  memoInfoList: {
    url: URLS.memoInfoList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  approvalNoticeInfoSetList: {
    url: URLS.approvalNoticeInfoSetList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  
  editMemoInfo: {
    url: URLS.editMemoInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },
  saveMemoInfo: {
      url: URLS.saveMemoInfo,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {
        Toast.show({
         content: <Loading/>,
        });
      },
    },
  saveInfoAfterBpm: {
      url: URLS.saveInfoAfterBpm,
      method:'POST',
      postDataFormat:'FORM',
      willFetch() {

      },
    },

  boardroomSetList: {
    mockUrl: 'query/meetingDetail.json',
    url: URLS.boardroomSetList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getBoardroomAdmin: {
    url: URLS.getBoardroomAdmin,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getAllApprovalUserIds: {
    url: URLS.getAllApprovalUserIds,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getQrcodeAttachment: {
    url: URLS.getQrcodeAttachment,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  boardRoomInfo: {
    mockUrl: 'query/mymeeting.json',
    url: URLS.boardRoomInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getJoinQsMeetingInfo: {
    mockUrl: 'query/mymeeting.json',
    url: URLS.getJoinQsMeetingInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  userSigned: {
    url: URLS.userSigned,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  urlconvert: {
    url: URLS.urlconvert,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  findTaskList: {
    url: URLS.findTaskList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  taskInfosCount: {
    url: URLS.taskInfosCount,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getTaskInfo: {
    url: URLS.getTaskInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  validateMeetingTime: {
    url: URLS.validateMeetingTime,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  changeProgress: {
    url: URLS.changeProgress,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
       content: <Loading/>,
      });
    },
  },

  saveTaskInfo: {
    url: URLS.saveTaskInfo,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
       content: <Loading/>,
      });
    },
  },

  deleteTaskInfo: {
    url: URLS.deleteTaskInfo,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
       content: <Loading/>,
      });
    },
  },

  getSignedInfo: {
    url: URLS.getSignedInfo,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getDoneTaskListByProcessId: {
    url: URLS.getDoneTaskListByProcessId,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  claimTask: {
    url: URLS.claimTask,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  queryFlowChart: {
    url: URLS.queryFlowChart,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  startProcess: {
    url: URLS.startProcess,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getMeetingRoomBpmInfo: {
    mockUrl: 'query/getSomeInfo.json',
    url: URLS.getMeetingRoomBpmInfo,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getCanBackActivity: {
    url: URLS.getCanBackActivity,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getCanJumpActivity: {
    url: URLS.getCanJumpActivity,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  createReadTask: {
    url: URLS.createReadTask,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  addSign: {
    url: URLS.addSign,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  forceEnd: {
    url: URLS.forceEnd,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  cancelProcess: {
    url: URLS.cancelProcess,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  recall: {
    url: URLS.recall,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  getNextActivity: {
    url: URLS.getNextActivity,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  suspendProcess: {
    url: URLS.suspendProcess,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  jump: {
    url: URLS.jump,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  transferFlow: {
    url: URLS.transferFlow,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  back: {
    url: URLS.back,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  sendFlow: {
    url: URLS.sendFlow,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  readCompleteTaskBatch: {
    url: URLS.readCompleteTaskBatch,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
        content: <Loading/>,
      });
    },
  },

  updateSignInfo: {
    url: URLS.updateSignInfo,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
       content: <Loading/>,
      });
    },
  },

  endApplyRecord: {
    url: URLS.endApplyRecord,
    method:'POST',
    postDataFormat:'FORM',
    willFetch() {
      Toast.show({
       content: <Loading/>,
      });
    },
  }
});
//流程接口方法
context.create('FlowModuleAPI', {
  getSendFileInfo: {
    mockUrl:'query/getSendFileInfo.json',
    url: URLS.getSendFileInfo,
    method:'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  sendFlow: {
    url: URLS.sendFlow,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  getReceiveFileInfo: {
    url: URLS.getReceiveFileInfo,
    method:'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  transferFlow: {
    url: URLS.transferFlow,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  createReadTask: {
    url: URLS.createReadTask,
    method:'POST',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  readCompleteTask: {
    url: URLS.readCompleteTask,
    method:'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  back: {
    url: URLS.back,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  getCanBackActivity: {
    mockUrl:'query/queryCanBack.json',
    url: URLS.getCanBackActivity,
    method:'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      // Toast.show({
      //   content: <Loading />
      // });
    },
  },
  suspendProcess: {
    url: URLS.suspendProcess,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  recall: {
    url: URLS.recall,
    method: 'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  getNextActivity: {
    mockUrl:'query/getNextActivity.json',
    url: URLS.getNextActivity,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  getListButtonsByCodes: {
    mockUrl:'query/saveForm.json',
    url: URLS.getListButtonsByCodes,
    method: 'GET',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
    },
  },
  getRelationProcess: {
    mockUrl:'query/getRelationProcess.json',
    url: URLS.getRelationProcess,
    method: 'GET',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
    },
  },
  queryFlowChart: {
    mockUrl:'query/queryProcessList.json',
    url: URLS.queryFlowChart,
    method:'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  claimTask: {
    mockUrl:'query/claimTask.json',
    url: URLS.claimTask,
    method: 'GET',
    willFetch() {
    }
  },
  addSign: {
    mockUrl:'query/addSign.json',
    url: URLS.addSign,
    method: 'GET',
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    }
  },
  getCanJumpActivity: {
    mockUrl:'query/getCanJumpActivity.json',
    url: URLS.getCanJumpActivity,
    method: 'GET',
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    }
  },
  jump: {
    mockUrl:'query/jump.json',
    url: URLS.jump,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    }
  },
  urgeFlow: {
    mockUrl:'',
    url: URLS.urgeFlow,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    }
  },
  getDoneTaskListByProcessId: {
    mockUrl:'query/getDoneTaskListByProcessId.json',
    url: URLS.getDoneTaskListByProcessId,
    method: 'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  cancelProcess: {
    mockUrl:'query/getDoneTaskListByProcessId.json',
    url: URLS.cancelProcess,
    method: 'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  forceEnd: {
    mockUrl:'query/getDoneTaskListByProcessId.json',
    url: URLS.forceEnd,
    method: 'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  getUndoTaskInfo: {
    mockUrl:'query/getUndoTaskInfo.json',
    url: URLS.getUndoTaskInfo,
    method: 'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  completeTaskBatch: {
    mockUrl:'query/getDoneTaskListByProcessId.json',
    url: URLS.completeTaskBatch,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  readCompleteTaskBatch: {
    mockUrl:'query/getDoneTaskListByProcessId.json',
    url: URLS.readCompleteTaskBatch,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />,
        duration:800
      });
    },
  },
  getPersonalPhrase: {
    mockUrl:'query/getPersonalPhrase.json',
    url: URLS.getPersonalPhrase,
    method: 'GET',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
    },
  },
  savePersonalPhrase: {
    mockUrl:'query/savePersonalPhrase.json',
    url: URLS.savePersonalPhrase,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
    },
  },
  saveForm: {
    mockUrl:'query/saveForm.json',
    url: URLS.saveForm,
    method: 'POST',
    postDataFomat: 'FORM',
    /*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
    },
  },
  
});
export default context.api;
